package client.core.io.conection;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;


import proprietes.ConnectProprietes;

public class ClientToServer extends Conection {

	public String createConection(String ip) {
		{
			try {
				clientSocket = new Socket(ip,
						ConnectProprietes.PORT.getiValue());
				outputStream = new PrintStream(clientSocket.getOutputStream());
				inputStream = new BufferedReader(new InputStreamReader(
						clientSocket.getInputStream()));
			} catch (UnknownHostException e) {
				return "Don't know about host ";
			} catch (IOException e) {
				return "Couldn't get I/O for the connection to the host ";
			}
		}
		return "ok";
	}

	public void sendRow(String... info) {
		for (String s : info) {
			outputStream.println(s);
		}
		outputStream.flush();
	}

	public String getRow() {
		String line = null;
		try {
				line = inputStream.readLine();
		} catch (IOException ex) {
		}
		return line;
	}

}
